/**
 * Created with IntelliJ IDEA.
 * User: liulinhui
 * Date: 18-10-8
 * Time: 下午7:16
 * Description: request.js
 */
import axios from 'axios';
import {Message} from 'element-ui';

const chainService = axios.create({
  baseURL: process.env.CHAIN_API, // api的base_url
  timeout: 300000 // request timeout
});

// request拦截器
chainService.interceptors.request.use(config => {
  // config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
  return config;
}, error => {
  // Do something with request error
  console.log(error); // for debug
  Promise.reject(error);
})

/**
 *datx节点服务接口拦截器
 */
chainService.interceptors.response.use(
  response => {
    if (response.data.code !== 200) {
      let error = response.data.message;
      console.log('err' + error);// for debug
      Message({
        message: error,
        type: 'error',
        duration: 2000
      });
      return Promise.reject(error);
    } else {
      return response.data
    }
  },
  error => {
    console.log('err' + error);// for debug
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    });
    return Promise.reject(error);
  });


export default chainService




